﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Speakup;
using System.Windows.Documents;
using System.Windows;
using System.Windows.Media;

namespace SpeakupUI
{
    class LegendPanel: ContentControl
    {
        static List<ClassStatus> SupportedStatuses;
        public static Dictionary<ClassStatus,String> StatusNames;


        static LegendPanel()
        {
            SupportedStatuses = new List<ClassStatus>();
            SupportedStatuses.Add(ClassStatus.Available);            
            SupportedStatuses.Add(ClassStatus.Reserved);
            SupportedStatuses.Add(ClassStatus.AvailableWaitList);
            SupportedStatuses.Add(ClassStatus.ReservedWaitList);

            StatusNames = new Dictionary<ClassStatus, string>();
            StatusNames[ClassStatus.Available] = "Available";
            StatusNames[ClassStatus.AvailableWaitList] = "Wait List only";
            StatusNames[ClassStatus.Reserved] = "Reserved by me";
            StatusNames[ClassStatus.ReservedWaitList] = "I'm on Wait List";
        }

        Grid Grid;

        public LegendPanel()
        {       
            Grid = new Grid();
           
            GroupBox groupBox = new GroupBox();
            groupBox.Content = Grid;
            groupBox.Header = "Legend";
            Content = groupBox;

            
            ColumnDefinition coldef = new ColumnDefinition();
            coldef.Width = new GridLength(1, GridUnitType.Star);
            Grid.ColumnDefinitions.Add(coldef);

            coldef = new ColumnDefinition();
            coldef.Width = new GridLength(1, GridUnitType.Star);
            Grid.ColumnDefinitions.Add(coldef);

            RowDefinition rowdef = new RowDefinition();
            rowdef.Height = GridLength.Auto;
            Grid.RowDefinitions.Add(rowdef);

            rowdef = new RowDefinition();
            rowdef.Height = GridLength.Auto;
            Grid.RowDefinitions.Add(rowdef);

            AddLegendItem(0, 0, StatusNames[ClassStatus.Available], 
                                ClassPanel.ClassBackgrounds[ClassStatus.Available]);

            AddLegendItem(0, 1, StatusNames[ClassStatus.Reserved], 
                                ClassPanel.ClassBackgrounds[ClassStatus.Reserved]);
            

            AddLegendItem(1, 0, StatusNames[ClassStatus.AvailableWaitList], 
                                ClassPanel.ClassBackgrounds[ClassStatus.AvailableWaitList]);
                    

            AddLegendItem(1, 1, StatusNames[ClassStatus.ReservedWaitList], 
                                ClassPanel.ClassBackgrounds[ClassStatus.ReservedWaitList]);
        
        }

        void AddLegendItem(int row, int column, string text, Brush background)
        {
            TextBlock name = new TextBlock();
            name.Text = text;
            name.TextAlignment = TextAlignment.Center;
            name.TextWrapping = TextWrapping.Wrap;

            Border border = new Border();
            border.BorderBrush = Brushes.Black;
            border.BorderThickness = new Thickness(1,1,1,1);
                        
            DockPanel panel = new DockPanel();
            panel.Background = background;
            panel.Children.Add(name);


            border.Child = panel;
            border.Margin = new Thickness(1);

            Grid.SetRow(border, row);
            Grid.SetColumn(border, column);
            Grid.Children.Add(border);
        }
    }


    
}
